# -*- coding: utf-8 -*-

__author__ = 'mariia.vitiuk'



class loginpage(object):

    def __init__(self, driver):
        self.driver = driver

    def login(driver):
        driver = self.driver
        driver.find_element_by_name("username").send_keys("admin")
        driver.find_element_by_name("password").send_keys("admin")
        driver.find_element_by_name("submit").click()

class mainpage(object):

    def __init__(self, driver):
        self.driver = driver

    def add_movie(self):
        driver = self.driver
        driver.find_element_by_xpath("//html/body/div[1]/div/div/section/nav/ul/li[1]/div/div/a").click()
        #driver.find_element_by_css("css=img[alt='Add movie']").click()

    '''
    thats draft for taining
    '''
    def movie_for_delete(self):
        driver = self.driver
        driver.find_element_by_xpath("html/body/div[1]/div/div/section/div[3]/a[1]/div").click()

    def search(self, searchval):
        driver = self.driver
        driver.find_element_by_id("q").send_keys(searchval)
        driver.send_keys(Keys.RETURN) # тоже что и ентер


class addmoviepage(object):

    def __init__(self, driver):
        self.driver = driver

    def imdb_number(self, val):
        driver = self.driver
        driver.find_element_by_name("imdbid").send_keys(val)

    def imdb_number_err(self):
        self.driver.find_element_by_class_name("error").get_attribute("text")

    def title(self, title):
        driver = self.driver
        driver.find_element_by_name("name").send_keys(title)

    def title_err(self):
        self.driver.find_element_by_name("required error").text()


    def aka(self, aka):
        driver = self.driver
        driver.find_element_by_name("aka").send_keys(aka)

    def year(self, year):
        driver = self.driver
        driver.find_element_by_name("year").send_keys(year)


    def save_button(self):
        driver = self.driver
        driver.find_element_by_name("submit").click()


class moviepage(object):

    def __init__(self, driver):
        self.driver = driver

    def remove_movie(self):
        driver = self.driver
        driver.find_element_by_xpath("//html/body/div[1]/div/div/section/nav/ul/li[5]/div/div/a").click()
        alert = driver.switch_to_alert()
        alert.accept()

